package com.patrol.patrol.utils;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.patrol.patrol.R;

public class DialogHelper {

    public static void showTwoChoiceDialog(final Context activity, String title, String content,
                                           String cancelText, String sureText, final DialogListenerEmpty cancelListener, final DialogListenerEmpty sureListener) {
        final Dialog dialog = new Dialog(activity, R.style.MyDialog);
        dialog.setContentView(R.layout.dialog_two_choice);
        dialog.setCanceledOnTouchOutside(true);
        TextView tv_title = dialog.findViewById(R.id.tv_title);
        TextView tv_content = dialog.findViewById(R.id.tv_content);
        TextView btn_cancel = dialog.findViewById(R.id.btn_cancel);
        TextView btn_sure = dialog.findViewById(R.id.btn_sure);
        tv_title.setText(title);
        tv_content.setText(content);
        btn_cancel.setText(cancelText);
        btn_sure.setText(sureText);
        btn_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (null != cancelListener) {
                    cancelListener.handleMessage();
                }
            }
        });
        btn_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (null != sureListener) {
                    sureListener.handleMessage();
                }
            }
        });
        dialog.findViewById(R.id.layout_pop).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                dialog.dismiss();
            }
        });
        dialog.show();
    }

    public interface DialogListenerEmpty {
        void handleMessage();
    }
}
